home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTAlert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  2.9 KB  |  123 lines

  1. /*    Displaying messages and getting input for LineMode Browser
  2. **    ==========================================================
  3. **
  4. **    REPLACE THIS MODULE with a GUI version in a GUI environment!
  5. **
  6. ** History:
  7. **       Jun 92 Created May 1992 By C.T. Barker
  8. **       Feb 93 Simplified, portablised TBL
  9. **       Sep 93 Corrected 3 bugs in HTConfirm() :-( AL
  10. */
  11.  
  12.  
  13. #include "HTUtils.h"
  14. #include "tcp.h"        /* for TOUPPER */
  15.  
  16. #include "HTAlert.h"
  17.  
  18. #include <ctype.h>         /* for toupper - should be in tcp.h */
  19.  
  20. #include "LYLeaks.h"
  21.  
  22. PUBLIC void HTAlert ARGS1(CONST char *, Msg)
  23. {
  24. #ifdef NeXTStep
  25.     NXRunAlertPanel(NULL, "%s", NULL, NULL, NULL, Msg);
  26. #else
  27.     fprintf(stderr, "WWW Alert:  %s\n", Msg);
  28. #endif
  29. }
  30.  
  31.  
  32. PUBLIC void HTProgress ARGS1(CONST char *, Msg)
  33. {
  34.     fprintf(stderr, "   %s ...\n", Msg);
  35. }
  36.  
  37.  
  38. PUBLIC BOOL HTConfirm ARGS1(CONST char *, Msg)
  39. {
  40.   char Reply[4];    /* One more for terminating NULL -- AL */
  41.   char *URep;
  42.   
  43.   fprintf(stderr, "WWW: %s (y/n) ", Msg);
  44.                        /* (y/n) came twice -- AL */
  45.  
  46.   fgets(Reply, 4, stdin); /* get reply, max 3 characters */
  47.   URep=Reply;
  48.   while (*URep) {
  49.     if (*URep == '\n') {
  50.     *URep = (char)0;    /* Overwrite newline */
  51.     break;
  52.     }
  53.     *URep=TOUPPER(*URep);
  54.     URep++;    /* This was previously embedded in the TOUPPER */
  55.                 /* call an it became evaluated twice because   */
  56.                 /* TOUPPER is a macro -- AL */
  57.   }
  58.  
  59.   if ((strcmp(Reply,"YES")==0) || (strcmp(Reply,"Y")==0))
  60.     return(YES);
  61.   else
  62.     return(NO);
  63. }
  64.  
  65. /*    Prompt for answer and get text back
  66. */
  67. PUBLIC char * HTPrompt ARGS2(CONST char *, Msg, CONST char *, deflt)
  68. {
  69.     char Tmp[200];
  70.     char * rep = 0;
  71.     fprintf(stderr, "WWW: %s", Msg);
  72.     if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
  73.     
  74.     fgets(Tmp, 200, stdin);
  75.     Tmp[strlen(Tmp)-1] = (char)0;    /* Overwrite newline */
  76.    
  77.     StrAllocCopy(rep, *Tmp ? Tmp : deflt);
  78.     return rep;
  79. }
  80.  
  81.  
  82. /*    Prompt for password without echoing the reply
  83. */
  84. PUBLIC char * HTPromptPassword ARGS1(CONST char *, Msg)
  85. {
  86.     char *result = NULL;
  87.     char *pw = (char*)getpass(Msg ? Msg : "Password: ");
  88.  
  89.     StrAllocCopy(result, pw);
  90.     return result;
  91. }
  92.  
  93.  
  94. /*    Prompt both username and password    HTPromptUsernameAndPassword()
  95. **    ---------------------------------
  96. ** On entry,
  97. **    Msg        is the prompting message.
  98. **    *username and
  99. **    *password    are char pointers; they are changed
  100. **            to point to result strings.
  101. **
  102. **            If *username is not NULL, it is taken
  103. **            to point to  a default value.
  104. **            Initial value of *password is
  105. **            completely discarded.
  106. **
  107. ** On exit,
  108. **    *username and *password point to newly allocated
  109. **    strings -- original strings pointed to by them
  110. **    are NOT freed.
  111. **    
  112. */
  113. PUBLIC void HTPromptUsernameAndPassword ARGS3(CONST char *,    Msg,
  114.                           char **,        username,
  115.                           char **,        password)
  116. {
  117.     if (Msg)
  118.     fprintf(stderr, "WWW: %s\n", Msg);
  119.     *username = HTPrompt("Username: ", *username);
  120.     *password = HTPromptPassword("Password: ");
  121. }
  122.  
  123.